home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 4 / The 640 Meg Shareware Studio CD-ROM Volume IV (Data Express)(1994).ISO / clang / xlib05.zip / XPBITMAP.ASM < prev    next >
Assembly Source File  |  1993-08-25  |  13KB  |  328 lines

  1. ;-----------------------------------------------------------------------
  2. ; MODULE XPBITMAP
  3. ;
  4. ; Planar Bitmap functions - System Ram <-> Video Ram
  5. ;
  6. ; Compile with Tasm.
  7. ; C callable.
  8. ;
  9. ;
  10. ; ****** XLIB - Mode X graphics library                ****************
  11. ; ******                                               ****************
  12. ; ****** Written By Themie Gouthas                     ****************
  13. ;
  14. ; egg@dstos3.dsto.gov.au
  15. ; teg@bart.dsto.gov.au
  16. ;-----------------------------------------------------------------------
  17.  
  18.  
  19. COMMENT $
  20.  
  21.   This module implements a set of functions to operate on planar bitmaps.
  22.   Planar bitmaps as used by these functions have the following structure:
  23.  
  24.   BYTE 0                 The bitmap width in bytes (4 pixel groups) range 1..255
  25.   BYTE 1                 The bitmap height in rows range 1..255
  26.   BYTE 2..n1             The plane 0 pixels width*height bytes
  27.   BYTE n1..n2            The plane 1 pixels width*height bytes
  28.   BYTE n2..n3            The plane 2 pixels width*height bytes
  29.   BYTE n3..n4            The plane 3 pixels width*height bytes
  30.  
  31.   These functions provide the fastest possible bitmap blts from system ram to
  32.   to video and further, the single bitmap is applicable to all pixel
  33.   allignments. The masked functions do not need separate masks since all non
  34.   zero pixels are considered to be masking pixels, hence if a pixel is 0 the
  35.   corresponding screen destination pixel is left unchanged.
  36.  
  37.  
  38. $
  39.  
  40. include xlib.inc
  41. include xpbitmap.inc
  42. LOCALS
  43.     .code
  44.  
  45. ;----------------------------------------------------------------------
  46. ; x_put_masked_pbm - mask write a planar bitmap from system ram to video ram
  47. ; all zero source bitmap bytes indicate destination byte to be left unchanged
  48. ;
  49. ; Source Bitmap structure:
  50. ;
  51. ;  Width:byte, Height:byte, Bitmap data (plane 0)...Bitmap data (plane 1)..,
  52. ;  Bitmap data (plane 2)..,Bitmap data (plane 3)..
  53. ;
  54. ;  note width is in bytes ie lots of 4 pixels
  55. ;
  56. ;  x_put_masked_pbm(X,Y,ScrnOffs,char far * Bitmap)
  57. ;
  58. ;
  59. ; LIMITATIONS: No clipping is supported
  60. ;              Only supports bitmaps with widths which are a multiple of
  61. ;              4 pixels
  62. ;
  63. ; Written by Themie Gouthas
  64. ;----------------------------------------------------------------------
  65. _x_put_masked_pbm  proc
  66.         ARG X:word,Y:word,ScrnOffs:word,Bitmap:dword
  67.     LOCAL Plane:byte,BMHeight:byte,LineInc:word=LocalStk
  68.     push  bp
  69.         mov   bp,sp
  70.     sub   sp,LocalStk                 ; Create space for local variables
  71.         push  si
  72.         push  di
  73.     push  ds
  74.     cld
  75.         mov   ax,SCREEN_SEG
  76.         mov   es,ax
  77.         mov   ax,[Y]                      ; Calculate dest screen row
  78.     mov   bx,[_ScrnLogicalByteWidth]  ;  by mult. dest Y coord by Screen
  79.     mul   bx                          ;  width then adding screen offset
  80.         mov   di,[ScrnOffs]               ;  store result in DI
  81.         add   di,ax
  82.         mov   cx,[X]                      ; Load X coord into CX and make a
  83.     mov   dx,cx                       ;  copy in DX
  84.     shr   dx,2                        ; Find starting byte in dest row
  85.     add   di,dx                       ;  add to DI giving screen offset of
  86.                                           ;  first pixel's byte
  87.         lds   si,[Bitmap]                 ; DS:SI -> Bitmap data
  88.         lodsw                             ; Al = B.M. width (bytes) AH = B.M.
  89.                                           ;  height
  90.     mov   [BMHeight],ah               ; Save source bitmap dimensions
  91.         xor   ah,ah                       ; LineInc = bytes to the begin.
  92.     sub   bx,ax                       ;  of bitmaps next row on screen
  93.     mov   [LineInc],bx
  94.     mov   bh,al                       ; Use bh as column loop count
  95.         and   cx,0003h                    ; mask X coord giving plane of 1st
  96.                       ; bitmap pixel(zero CH coincidentally)
  97.     mov   ah,11h                      ; Init. mask for VGA plane selection
  98.         shl   ah,cl                       ; Shift for starting pixel plane
  99.         mov   dx,SC_INDEX                 ; Prepare VGA for cpu to video writes
  100.         mov   al,MAP_MASK
  101.         out   dx,al
  102.         inc   dx
  103.     mov   [Plane],4                   ; Set plane counter to 4
  104. @@PlaneLoop:
  105.         push  di                          ; Save bitmap's start dest. offset
  106.         mov   bl,[BMHeight]               ; Reset row counter (BL)
  107.         mov   al,ah
  108.         out   dx,al                       ; set vga write plane
  109. @@RowLoop:
  110.     mov   cl,bh                       ; Reset Column counter cl
  111. @@ColLoop:
  112.     lodsb                             ; Get next source bitmap byte
  113.     or    al,al                       ; If not zero then write to dest.
  114.     jz    @@NoPixel                   ; otherwise skip to next byte
  115.     mov   es:[di],al
  116. @@NoPixel:
  117.     inc   di
  118.     loop  @@ColLoop                   ; loop if more columns left
  119.     add   di,[LineInc]                ; Move to next row
  120.         dec   bl                          ; decrement row counter
  121.         jnz   @@RowLoop                   ; Jump if more rows left
  122.         pop   di                          ; Restore bitmaps start dest byte
  123.         rol   ah,1                        ; Shift mask for next plane
  124.     adc   di,0                        ; If wrapped increment dest address
  125.     dec   [Plane]                     ; Decrement plane counter
  126.         jnz   @@PlaneLoop                 ; Jump if more planes left
  127.  
  128.         pop   ds                          ; restore data segment
  129.         pop   di                          ; restore registers
  130.         pop   si
  131.         mov   sp,bp                       ; dealloc local variables
  132.         pop   bp
  133.         ret
  134. _x_put_masked_pbm  endp
  135.  
  136.  
  137. ;----------------------------------------------------------------------
  138. ; x_put_pbm - Write a planar bitmap from system ram to video ram
  139. ;
  140. ; Source Bitmap structure:
  141. ;
  142. ;  Width:byte, Height:byte, Bitmap data (plane 0)...Bitmap data (plane 1)..,
  143. ;  Bitmap data (plane 2)..,Bitmap data (plane 3)..
  144. ;
  145. ;  note width is in bytes ie lots of 4 pixels
  146. ;
  147. ;  x_put_pbm(X,Y,ScrnOffs,char far * Bitmap)
  148. ;
  149. ;
  150. ; LIMITATIONS: No clipping is supported
  151. ;              Only supports bitmaps with widths which are a multiple of
  152. ;              4 pixels
  153. ; FEATURES   : Automatically selects REP MOVSB or REP MOVSW  depending on
  154. ;              source bitmap width, by modifying opcode ;-).
  155. ;
  156. ; Written by Themie Gouthas
  157. ;----------------------------------------------------------------------
  158. _x_put_pbm  proc
  159.     ARG X:word,Y:word,ScrnOffs:word,Bitmap:dword
  160.     LOCAL Plane:byte,BMHeight:byte,LineInc:word=LocalStk
  161.     push  bp
  162.         mov   bp,sp
  163.     sub   sp,LocalStk                 ; Create space for local variables
  164.     push  si
  165.         push  di
  166.     push  ds
  167.     cld
  168.         mov   ax,SCREEN_SEG
  169.         mov   es,ax
  170.         mov   ax,[Y]                      ; Calculate dest screen row
  171.     mov   bx,[_ScrnLogicalByteWidth]  ;  by mult. dest Y coord by Screen
  172.     mul   bx                          ;  width then adding screen offset
  173.         mov   di,[ScrnOffs]               ;  store result in DI
  174.         add   di,ax
  175.         mov   cx,[X]                      ; Load X coord into CX and make a
  176.     mov   dx,cx                       ;  copy in DX
  177.     shr   dx,2                        ; Find starting byte in dest row
  178.     add   di,dx                       ;  add to DI giving screen offset of
  179.                                           ;  first pixel's byte
  180.         lds   si,[Bitmap]                 ; DS:SI -> Bitmap data
  181.         lodsw                             ; Al = B.M. width (bytes) AH = B.M.
  182.                                           ;  height
  183.         mov   [BMHeight],ah               ; Save source bitmap dimensions
  184.         xor   ah,ah                       ; LineInc = bytes to the begin.
  185.     sub   bx,ax                       ;  of bitmaps next row on screen
  186.     mov   [LineInc],bx
  187.     mov   bh,al
  188.                       ; Self Modifying, Shame, shame shame..
  189.         and   cx,0003h                    ; mask X coord giving plane of 1st
  190.                                           ; bitmap pixel(zero CH coincidentally)
  191.     mov   ah,11h                      ; Init. mask for VGA plane selection
  192.         shl   ah,cl                       ; Shift for starting pixel plane
  193.         mov   dx,SC_INDEX                 ; Prepare VGA for cpu to video writes
  194.         mov   al,MAP_MASK
  195.         out   dx,al
  196.         inc   dx
  197.     mov   [Plane],4                   ; Set plane counter to 4
  198. @@PlaneLoop:
  199.         push  di
  200.     mov   bl,[BMHeight]
  201.         mov   al,ah
  202.         out   dx,al
  203. @@RowLoop:
  204.     mov   cl,bh
  205.     shr   cl,1
  206.     rep   movsw                       ; Copy a complete row for curr plane
  207.     adc   cl,0
  208.     rep   movsb
  209.     add   di,[LineInc]                ; Move to next row
  210.         dec   bl                          ; decrement row counter
  211.         jnz   @@RowLoop                   ; Jump if more rows left
  212.         pop   di                          ; Restore bitmaps start dest byte
  213.         rol   ah,1                        ; Shift mask for next plane
  214.     adc   di,0                        ; If wrapped increment dest address
  215.     dec   [Plane]                     ; Decrement plane counter
  216.         jnz   @@PlaneLoop                 ; Jump if more planes left
  217.  
  218.         pop   ds                          ; restore data segment
  219.         pop   di                          ; restore registers
  220.         pop   si
  221.         mov   sp,bp                       ; dealloc local variables
  222.         pop   bp
  223.         ret
  224. _x_put_pbm  endp
  225.  
  226. ;----------------------------------------------------------------------
  227. ; x_get_pbm - Read a planar bitmap to system ram from video ram
  228. ;
  229. ; Source Bitmap structure:
  230. ;
  231. ;  Width:byte, Height:byte, Bitmap data (plane 0)...Bitmap data (plane 1)..,
  232. ;  Bitmap data (plane 2)..,Bitmap data (plane 3)..
  233. ;
  234. ;  note width is in bytes ie lots of 4 pixels
  235. ;
  236. ;  x_get_pbm(X,Y,BMwidth,BMheight,ScrnOffs,char far * Bitmap)
  237. ;
  238. ;
  239. ; LIMITATIONS: No clipping is supported
  240. ;              Only supports bitmaps with widths which are a multiple of
  241. ;              4 pixels
  242. ; FEATURES   : Automatically selects REP MOVSB or REP MOVSW  depending on
  243. ;              source bitmap width, by modifying opcode ;-).
  244. ;
  245. ; Written by Themie Gouthas
  246. ;----------------------------------------------------------------------
  247. _x_get_pbm  proc
  248.     ARG X:word,Y:word,SrcWidth:byte,SrcHeight:byte,ScrnOffs:word,Bitmap:dword
  249.     LOCAL Plane:byte,LineInc:word=LocalStk
  250.     push  bp
  251.         mov   bp,sp
  252.     sub   sp,LocalStk                 ; Create space for local variables
  253.         push  si
  254.         push  di
  255.         push  ds
  256.     cld
  257.  
  258.     mov   ax,[Y]                      ; Calculate screen row
  259.     mov   bx,[_ScrnLogicalByteWidth]  ;  by mult. Y coord by Screen
  260.     mul   bx                          ;  width then adding screen offset
  261.     mov   si,[ScrnOffs]               ;  store result in SI
  262.     add   si,ax
  263.         mov   cx,[X]                      ; Load X coord into CX and make a
  264.     mov   dx,cx                       ;  copy in DX
  265.     shr   dx,2                        ; Find starting byte in screen row
  266.     add   si,dx                       ;  add to SI giving screen offset of
  267.                       ;  first pixel's byte
  268.     mov   ax,SCREEN_SEG
  269.     mov   ds,ax
  270.     les   di,[Bitmap]                 ; ES:DI -> Bitmap data
  271.     mov   al,[SrcWidth]
  272.     mov   ah,[SrcHeight]
  273.     stosw                             ; Al = B.M. width (bytes) AH = B.M.
  274.                                           ;  height
  275.         xor   ah,ah                       ; LineInc = bytes to the begin.
  276.     sub   bx,ax                       ;  of bitmaps next row on screen
  277.     mov   [LineInc],bx
  278.     mov   bh,al
  279.                       ; Self Modifying, Shame, shame shame..
  280.         and   cx,0003h                    ; mask X coord giving plane of 1st
  281.                                           ; bitmap pixel(zero CH coincidentally)
  282.     mov   ah,11h                      ; Init. mask for VGA plane selection
  283.     shl   ah,cl                       ; Shift for starting pixel plane
  284.     mov   dx,GC_INDEX                 ; Prepare VGA for cpu to video reads
  285.     mov   al,READ_MAP
  286.         out   dx,al
  287.         inc   dx
  288.     mov   [Plane],4                   ; Set plane counter (BH) to 4
  289.     mov   al,cl
  290. @@PlaneLoop:
  291.     push  si
  292.     mov   bl,[SrcHeight]
  293.         out   dx,al
  294. @@RowLoop:
  295.     mov   cl,bh
  296.     shr   cl,1
  297.     rep   movsw                       ; Copy a complete row for curr plane
  298.     adc   cl,0
  299.     rep   movsb
  300.     add   si,[LineInc]                ; Move to next row
  301.         dec   bl                          ; decrement row counter
  302.         jnz   @@RowLoop                   ; Jump if more rows left
  303.     pop   si                          ; Restore bitmaps start dest byte
  304.  
  305.     inc   al                          ; Select next plane to read from
  306.     and   al,3                        ;
  307.  
  308.     rol   ah,1                        ; Shift mask for next plane
  309.     adc   si,0                        ; If wrapped increment dest address
  310.     dec   [Plane]                     ; Decrement plane counter
  311.     jnz   @@PlaneLoop                 ; Jump if more planes left
  312.  
  313.         pop   ds                          ; restore data segment
  314.         pop   di                          ; restore registers
  315.         pop   si
  316.         mov   sp,bp                       ; dealloc local variables
  317.         pop   bp
  318.         ret
  319. _x_get_pbm  endp
  320.  
  321.  
  322.  
  323.  
  324.     end
  325.  
  326.  
  327.  
  328.